package com.simoniu.first;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value="/hello",loadOnStartup =1)
public class HelloServlet extends HttpServlet {

    public HelloServlet(){
        System.out.println("执行了HelloServlet的构造方法...");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        //请求重定向
        //resp.sendRedirect(req.getContextPath()+"/test");
        //请求转发
        req.getRequestDispatcher("/test").forward(req,resp);

    }

    public void destroy() {
    }
}